package com.wocao.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wocao.system.entity.SysUserRoleDo;
import com.wocao.system.mapper.SysUserRoleMapper;
import com.wocao.system.service.SysUserRoleService;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 用户角色关系接口实现类
 *
 * @author sunhao
 * @date 2021/8/14
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRoleDo> implements
        SysUserRoleService {

    @Override
    public List<SysUserRoleDo> listSysUserRolesByUserId(String userId) {
        QueryWrapper<SysUserRoleDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return this.list(queryWrapper);
    }

    @Override
    public void addUserRole(String userId, String roleId) {
        SysUserRoleDo sysUserRoleDo = new SysUserRoleDo();
        sysUserRoleDo.setUserId(userId);
        sysUserRoleDo.setRoleId(roleId);
        this.save(sysUserRoleDo);
    }

    @Override
    public void deleteUserRole(String userId) {
        QueryWrapper<SysUserRoleDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        this.remove(queryWrapper);
    }

}
